package com.fengye.middleware.rabbitmq.spring.event.demo;

import com.fengye.middleware.rabbitmq.spring.event.domain.LoginEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * LoginEvent 消息发起者
 * @author sky
 * @date 2021年06月09日 10:17 上午
 */
@Component
@Slf4j
public class LoginEventPublisher {

    @Autowired
    private ApplicationEventPublisher publisher;

    public void sendMsg(String name) {
        String ip = "127.0.0.1";
        String loginTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        LoginEvent loginEvent = new LoginEvent(this, name, loginTime, ip);
        publisher.publishEvent(loginEvent);
    }
}
